package cn.taofuxn.sale.controller;

import cn.taofuxn.sale.controller.data.AddGoodsRequest;
import cn.taofuxn.sale.controller.data.ModifyGoodsRequest;
import cn.taofuxn.sale.controller.data.QueryOrderRequest;
import cn.taofuxn.sale.service.GoodsService;
import cn.taofuxn.sale.service.data.base.BaseResult;
import io.swagger.annotations.Api;
import org.hibernate.validator.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * ProjectName : GeekSaleSystem
 * PackageName : cn.taofuxn.sale.controller
 * Created by Wong
 * Date: 2018/3/20
 * Time: 15:24
 */
@Api(value = "GoodsController" ,description = "商品管理")
@RestController
@RequestMapping(value = "/goods")
public class GoodsController {
	
	@Autowired
	private GoodsService m_GoodsService;
	
	@RequestMapping(value = "/getGoods",method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
	public BaseResult getGoods(@Valid  @RequestBody QueryOrderRequest vRequest){
		return  m_GoodsService.getGoods(vRequest.getPage(),vRequest.getPagesize(),vRequest.getStartTime(),vRequest.getEndTime());
	}
	
	@RequestMapping(value = "/addGoods",method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
	public BaseResult addGoods(@Valid  @RequestBody AddGoodsRequest vRequest){
		return m_GoodsService.addGoods(vRequest);
	}
	
	@RequestMapping(value = "/modifyGoods",method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
	public BaseResult modifyGoods(@Valid @RequestBody ModifyGoodsRequest vRequest){
		return m_GoodsService.modifyGoods(vRequest);
	}
	
	@RequestMapping(value = "/deleteProducer",method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
	public BaseResult deleteGoods(@Valid @NotBlank String goodsId){
		return m_GoodsService.deleteGoods(goodsId);
	}

}
